import { defineStore } from "pinia"
import { getMenuListApi } from "@/api/modules/login"
import { getFlatMenuList, getAllBreadcrumbList, getShowMenuList } from '@/utils'
export const useAuthStore = defineStore("pinia-auth", {
    state: () => ({
        menuList: []
    }),
    actions: {
        // 获取菜单列表
        getMenuList () {
            const { data } = getMenuListApi()
            this.menuList = data
        }
    },
    getters: {
        // 菜单列表
        getMenuListState: (state) => state.menuList,
        // 菜单权限列表 ==> 左侧菜单栏渲染，需要剔除 isHide == true
        showMenuListGet: state => getShowMenuList(state.menuList),
        // 菜单权限列表 ==> 扁平化之后的一维数组菜单，主要用来添加动态路由
        flatMenuListGet: state => getFlatMenuList(state.menuList),
        breadcrumbListGet: state => getAllBreadcrumbList(state.menuList)
    }
})